//
//  ViewController.m
//  LRCAnalyze
//
//  Created by 小草毋正 on 2018/1/4.
//  Copyright © 2018年 zwc. All rights reserved.
//

#import "ViewController.h"

#import "CLLRC.h"

#import "CLLRCShowView.h"

@interface ViewController () {
    
    CLLRC *lcr;
    
    NSInteger timeMM;
    
    NSInteger selectedIndex;
}

@property (nonatomic, strong) NSTimer *timer;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;

@property (nonatomic, strong) CLLRCShowView *lcrView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    timeMM = 0;
    selectedIndex = -1;
    
    [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"10736444" ofType:@"lrc"];
    NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
    lcr = [[CLLRC alloc] initWithFileUrl:url];
    
    
    self.lcrView = [[CLLRCShowView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64)];
    self.lcrView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:self.lcrView];
    self.lcrView.filerUrl = url;
}


- (NSTimer *)timer {
    if(!_timer){
        _timer = [NSTimer timerWithTimeInterval:.5 target:self selector:@selector(timeAdd) userInfo:nil repeats:YES];
    }
    return _timer;
}

- (void)timeAdd {
    
    timeMM += 500;
    
    self.lcrView.currentTime = timeMM;
    
    
    
    if(timeMM > 0){
        //显示时间
        NSInteger min = timeMM / (60 * 1000);
        NSInteger sec = timeMM / (1000);
        self.timeLabel.text = [NSString stringWithFormat:@"%02ld:%02ld", min, sec];
    } 
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
